<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

$params = array("nomeSearch"=>"teste", 
    "sobrenomeSearch"=>"",
    "emailSearch"=>"teste@teste.com.br");

$whereSql = "WHERE ";

       foreach ($params as $key=>$value){
           
           
           if(empty($value)){
            switch ($key){
                case 'nomeSearch':
                    
                    $whereSql= $whereSql." PES_st_nome LIKE %".$params['nomeSearch']."% ";
                    if(strlen($whereSql)>6){
               
                        $whereSql = $whereSql." AND "; 
                    }
                case 'sobrenomeSearch':
                    if(strlen($whereSql)>6){
               
                        $whereSql = $whereSql." AND "; 
                    }
                    $whereSql= $whereSql." PES_st_sobrenome LIKE %".$params['sobrenomeSearch']."% ";
                case 'emailSearch':
                    if(strlen($whereSql)>6){
               
                        $whereSql = $whereSql." AND "; 
                    }
                    $whereSql= $whereSql." CON_st_email LIKE %".$params['emailSearch']."% ";
                default :"";
            }
            
           }
        }
        
        
  echo $whereSql;      